import { reactive } from 'vue';

export default function importConfig(props, emits) {
  const { emit } = emits;
  const base = reactive<any>({
    showConfig: null,
  });

  /**
   * @exports init 初始化
   */
  const init = () => {
    base.showConfig = props.config;
    console.log(base.showConfig);
  };

  /**
   * @exports tapConditional 监听回车及其点击搜索后触发的事件
   */
  const tapConditional = () => {
    emitCommand();
  };

  /**
   * @exports reset 清空命令
   */
  const reset = () => {
    base.showConfig.map((res: any) => {
      res.value = null;
    });
    emitCommand();
  };

  /**
   * @exports emitCommand  emit指令集合
   */
  const emitCommand = () => {
    /**
     * 更新 v-model:config
     */
    emit('update:config', base.showConfig);
    /**
     * 通知事件
     */
    emit('tapDate', base.showConfig);
  };

  return {
    base,
    init,
    tapConditional,
    reset,
  };
}
